class Solution {
public:
    int findPoisonedDuration(vector<int>& timeSeries, int duration)
    {
        int sum = 0, n = timeSeries.size();
        for (int i = 0; i < n; i++)
        {
            if (i == n - 1 || timeSeries[i] + duration - 1 < timeSeries[i + 1])
                sum += duration;
            else
                sum += timeSeries[i + 1] - timeSeries[i];

        }

        return sum;

    }
};